package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.prd.model.OaRewardsAndPunishmentsDO;
import com.prd.mapper.OaRewardsAndPunishmentsMapper;
import com.prd.service.OaRewardsAndPunishmentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 * 人事奖惩管理数据表 服务实现类
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-29
 */
@Service
public class OaRewardsAndPunishmentsServiceImpl extends ServiceImpl<OaRewardsAndPunishmentsMapper, OaRewardsAndPunishmentsDO> implements OaRewardsAndPunishmentsService {

    @Autowired
    private OaRewardsAndPunishmentsMapper mapper;

    /**
     * 获取奖惩列表
     * @return
     */
    @Override
    public JsonData getList() {
        return JsonData.buildSuccess(mapper.selectList(new QueryWrapper<>()));
    }

    /**
     * 获取奖惩分页列表
     * @param status
     * @param type
     * @param size
     * @param page
     * @return
     */
    @Override
    public JsonData getPage(Integer status, Integer type, Integer size, Integer page) {

        Page<OaRewardsAndPunishmentsDO> doPage = new Page<>(size,page);

        Page<OaRewardsAndPunishmentsDO> resultPage = mapper.selectPage(doPage, new LambdaQueryWrapper<OaRewardsAndPunishmentsDO>()
                .eq(status != null, OaRewardsAndPunishmentsDO::getStatus, status)
                .eq(type != null, OaRewardsAndPunishmentsDO::getType, type));

        HashMap<String, Object> resultMap = new HashMap<>(3);
        resultMap.put("total",resultPage.getTotal());
        resultMap.put("pages",resultPage.getPages());
        resultMap.put("data",resultPage.getRecords());

        return JsonData.buildSuccess(resultMap);
    }

    /**
     * 根据id获取奖惩详情
     * @param id
     * @return
     */
    @Override
    public JsonData getDetailById(Long id) {
        return JsonData.buildSuccess(mapper.selectById(id));
    }
}
